package com.wicket.tutorial;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.PageParameters;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.markup.html.CSSPackageResource;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.resources.CompressedResourceReference;
import org.apache.wicket.markup.repeater.RepeatingView;

import com.wicket.tutorial.sections.advaced.AdvancedSection;
import com.wicket.tutorial.sections.basic.SectionOne;

/**
 * Homepage
 */
public abstract class BasePage extends WebPage {

	private static final long serialVersionUID = 1L;

	private static final ResourceReference CSS = new CompressedResourceReference(BasePage.class, "application.css");
	
	private List<TutorialSection> sections = new ArrayList<TutorialSection>();
	
    /**
	 * Constructor that is invoked when page is invoked without a session.
	 * 
	 * @param parameters
	 *            Page parameters
	 */
    public BasePage(final PageParameters parameters) {
    	add(CSSPackageResource.getHeaderContribution(CSS));
    	sections.add(new SectionOne());
    	sections.add(new AdvancedSection());
    
    	
    	RepeatingView section = new RepeatingView("sections");
    	add(section);
    	for(TutorialSection ts: sections) {
    		WebMarkupContainer wm = new WebMarkupContainer(section.newChildId());
    		section.add(wm);
    		wm.add(new Label("title", ts.getTitle()));    	
    		RepeatingView pages = new RepeatingView("pages");
			wm.add(pages);
    		for(TutorialLink tl: ts.getPages()) {    			
    			WebMarkupContainer wm1 = new WebMarkupContainer(pages.newChildId());
    			pages.add(wm1);
        		BookmarkablePageLink<Void> link = new BookmarkablePageLink<Void>("link", tl.getPageClass());
        		wm1.add(link);
        		link.add(new Label("title", tl.getTitle()));
    		}
    	}
    	

    }
}
